package org.duoyi.striver.gui;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import lombok.Getter;

import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 任务列表
 *
 * @author chenyuheng create class on 2021-05-10
 */
@Getter
public class TaskItem {

    private String name;

    private HBox box;

    private CheckBox checkBox;

    private ChoiceBox<String> skillBox;

    private ChoiceBox<String> lineupBox;

    public TaskItem(String name) {
        this.name = name;

        checkBox = new CheckBox();
        Label label = new Label(name);
        label.setFont(new Font(15));

        Font font = new Font(10);

        Label skillLabel = new Label("  技能：");
        skillLabel.setFont(font);
        ObservableList<String> skills = FXCollections.observableArrayList();
        skills.add("无");
        skills.addAll(IntStream.rangeClosed(1, 10).mapToObj(String::valueOf).collect(Collectors.toList()));
        skillBox = new ChoiceBox<>(skills);
        skillBox.setPrefWidth(50);

        Label lineupLabel = new Label("  阵容：");
        lineupLabel.setFont(font);
        ObservableList<String> lineups = FXCollections.observableArrayList();
        lineups.add("无");
        lineups.addAll(IntStream.rangeClosed(1, 3).mapToObj(String::valueOf).collect(Collectors.toList()));
        lineupBox = new ChoiceBox<>(lineups);
        lineupBox.setPrefWidth(50);


        box = new HBox();
        box.getChildren().addAll(checkBox, label, skillLabel, skillBox, lineupLabel, lineupBox);
    }

    public void enable() {
        this.checkBox.setDisable(false);
        this.skillBox.setDisable(false);
        this.lineupBox.setDisable(false);
    }

    public void disable() {
        this.checkBox.setDisable(true);
        this.skillBox.setDisable(true);
        this.lineupBox.setDisable(true);
    }

    @Override
    public String toString() {
        return name;
    }
}
